package com.sneakxy.mybatis.commons.repository;

import java.io.Serializable;
import java.util.List;
import java.util.Optional;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.repository.Repository;

import com.sneakxy.mybatis.commons.repository.query.domain.Criteria;

/**
 * @author 潜行的虚影
 */
@NoRepositoryBean
public interface ExpandRepository<T, ID extends Serializable> extends Repository<T, ID> {

	String getTableName();
	
	<S extends T> S save(S entity, String table_name);
	
	<S extends T> void update(S entity, String table_name, Criteria<S> criteria);
	
	void deleteById(ID id, String table_name);
	
	void delete(Criteria<T> criteria, String table_name);
	
	boolean existsById(ID id, String table_name);
	
	boolean exists(Criteria<T> criteria, String table_name);
	
	Optional<T> findById(ID id, String table_name);
	
	T findOne(Criteria<T> criteria, String table_name);

	List<T> findAll(Criteria<T> criteria, String table_name);
	
	Page<T> findAll(Criteria<T> criteria, String table_name, Pageable pageable);
	
	List<T> findAll(Criteria<T> criteria, String table_name, Sort sort);
	
	long count(Criteria<T> criteria, String table_name);
	
	long count(String table_name);
	
	Iterable<T> findAll(String table_name);
	
	Iterable<T> findAll(String table_name, Sort sort);
	
	Page<T> findAll(String table_name, Pageable pageable);
	
	void deleteAll(String table_name);
	
	boolean isNew(T entity);
	
}
